import '../util/_base_export.dart';

class OrderDetailBloc with ChangeNotifier {
  // static String last_version = '';
  // static bool force_update = false;
  // static Map popup_window = {};
  // static List category_list = [];
  // static Map creditcard = {};
  // static Map user_addr = {};
  // static String cs_cell = '';
  // static Map data = {};

  int payment_channel = 2;

  void clear() {
    payment_channel = 2;
    // await initLoad();
  }

  void updatePaymentChannel(int iv_channel) {
    payment_channel = iv_channel;
  }

  findPaymentChannelDescr(Map im_order, int iv_channel) {
    var lm_item = {};
    if (im_order.isNotEmpty){
      lm_item = im_order['available_payment_channels']
          .firstWhere((item) => item['channel'] == iv_channel, orElse: () => {});
    }
    if (lm_item.isNotEmpty) {
      return lm_item['descr'];
    } else
      return '';
  }

  orderRepay(Map<String, dynamic> im_param) async {
    Map<String, dynamic> lm_param = {};
    lm_param.addAll(im_param);

    var lm_result = await AppSession.appReq.futureWrapper(
      ApiConst.httpPost,
      ApiServer.prod + ApiUri.order_repay,
      {},
      lm_param,
      true,
      true,
    );

    if (lm_result['ev_error'] == 0)
      return lm_result['ev_result'];
    else if ((lm_result['ev_message'] ?? '').isNotEmpty) {
      AppPopupService.showAlertSimple('E', '出错啦', lm_result['ev_message']);
      return {};
    }
  }

  // initLoad() async {
  //   var lm_initapp = await AppSession.appReq.futureWrapper(
  //     ApiConst.httpGet,
  //     ApiServer.prod + ApiUri.init_app,
  //     {},
  //     {},
  //     true, //(AppSession.authortoken ?? '').isNotEmpty,
  //     false,
  //   );

  //   if ((lm_initapp['ev_result'] ?? {}).isNotEmpty) {
  //     var lm_result = lm_initapp['ev_result'];

  //     if ((lm_result['latest_version'] ?? '').isNotEmpty)
  //       last_version = lm_result['latest_version'];
  //     if (lm_result['force_update'] != null) force_update = lm_result['force_update'];
  //     if ((lm_result['popup_window'] ?? {}).isNotEmpty) popup_window = lm_result['popup_window'];
  //     if ((lm_result['user_address'] ?? {}).isNotEmpty) {
  //       AppSession.userAddr = lm_result['user_address'];
  //     }

  //     if ((lm_result['payment_cards'] ?? {}).isNotEmpty) if ((lm_result['payment_cards']['2'] ?? {})
  //         .isNotEmpty) AppSession.creditcard = lm_result['payment_cards']['2'];
  //     if ((lm_result['category_list'] ?? []).isNotEmpty) category_list = lm_result['category_list'];
  //     if ((lm_result['cs_cell'] ?? '').isNotEmpty) cs_cell = lm_result['cs_cell'];
  //     data = lm_result;
  //   }
  // }

}
